/* 
 * File:   RegularGridIterator.h
 * Author: walther
 *
 * Created on October 20, 2012, 9:25 PM
 */

#ifndef REGULARGRIDITERATOR_H
#define	REGULARGRIDITERATOR_H

#include "GridIterator.h"
#include "RegularGrid.h"

class RegularGridIterator : public GridIterator
{
public:
    /**
     * Constructor
     * @param grid Regular grid that will be traversed 
     * @param ray Ray that will traverse the grid
     */
    RegularGridIterator( RegularGrid* grid, Ray& ray );
    
    /**
     * Destructor
     */
    virtual ~RegularGridIterator();
    
    /**
     * @return Next cell intercepted by the ray
     */
    GridCell* next();
    
private:
    void computeTraversalParameters();
    
    /** Pointer to the grid */
    RegularGrid* _grid;
    
    /** Next ray parameter value that will cross a vertical cell edge */
    double _nextX;
    
    /** Next ray parameter value that will cross a horizontal cell edge */
    double _nextY;
    
    /** Next ray parameter value that will cross a vertical cell edge */
    double _nextZ;
    
    /** Size of the step in each of the coordinates */
    double _deltaX, _deltaY, _deltaZ;
    
    /** Current cell indices */
    int _currentCellX, _currentCellY, _currentCellZ;
    
    /** Step in each direction. Can be 1 or -1 if it goes up or down */
    int _stepX, _stepY, _stepZ;    
};

#endif	/* REGULARGRIDITERATOR_H */

